home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / DESKLIBC / SOURCES.ZIP / DeskLib / !DLSources / Libraries / Window / c / GainCaret < prev    next >
Text File  |  1995-07-08  |  3KB  |  90 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Window.GainCaret.c
  12.     Author:  Copyright © 1995 Cy Booker
  13.     Version: 1.01 (21 Jun 1995)
  14.     Purpose: High-level window management functions
  15.     Mods:    Julian Smith - Modified to cope with Icon_SetCaret
  16.                             which doesn't return an (os_error *)
  17.                             yet.
  18. */
  19.  
  20. #include <stdlib.h>     /* malloc */
  21.  
  22. #include "DeskLib:Window.h"
  23. #include "DeskLib:Icon.h"
  24. #include "DeskLib:WimpSWIs.h"
  25.  
  26.  
  27. extern os_error *Window_GainCaret(window_handle window) {
  28.   os_error      *error;
  29.   caret_block   caretblock;
  30.   window_info   windowinfo;
  31.  
  32.   if (!window) {
  33.     /* disown caret
  34.      */
  35.     caretblock.window = -1;
  36.     caretblock.icon   = -1;
  37.     caretblock.height = 0;
  38.     caretblock.index  = -1;
  39.     return Wimp_SetCaretPosition(&caretblock);
  40.   }
  41.   error = Wimp_GetCaretPosition(&caretblock);
  42.   if (error) {
  43.     return error;
  44.   }
  45.   if ((caretblock.window == window) && (caretblock.icon != -1)) {
  46.     /* already in the window, in an icon, so abort now
  47.      */
  48.     return NULL;
  49.   }
  50.   error = Window_GetInfo3(window, &windowinfo);
  51.   if (error) {
  52.     return error;
  53.   }
  54.   if (windowinfo.block.numicons > 0) {
  55.     icon_handle   *buffer;
  56.  
  57.     buffer = malloc((1+windowinfo.block.numicons)*sizeof(*buffer));
  58.     if (buffer) {
  59.       int               mask, settings;
  60.       icon_handle       icon;
  61.  
  62.       mask = icon_TEXT |
  63.              (icon_BUTTONTYPE * 0x0f) |
  64.              icon_SHADED |
  65.              icon_DELETED;
  66.       settings = icon_TEXT |
  67.                  (icon_BUTTONTYPE * iconbtype_WRITECLICKDRAG);  /* note! */
  68.       error = Wimp_WhichIcon(window, buffer, mask, settings);
  69.       icon = buffer[0];
  70.       free(buffer);
  71.       if (error) {
  72.         return error;
  73.       }
  74.       if (icon != -1) {
  75.         /*return Icon_SetCaret(window, icon);*/
  76.         Icon_SetCaret(window, icon);
  77.         return NULL;
  78.         /* JS - Icon_SetCaret doesn't return an (os_error *) yet...    */
  79.       }
  80.     }
  81.   }
  82.   caretblock.window   = window;
  83.   caretblock.icon     = -1;
  84.   caretblock.offset.x = 0;
  85.   caretblock.offset.y = 0;
  86.   caretblock.height   = 1 << 25;                /* caret is invisible */
  87.   caretblock.index    = -1;
  88.   return Wimp_SetCaretPosition(&caretblock);
  89. }
  90.